<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<%@ include file="../common/static.html" %>
</head>

<body>
	<div id="maingrid" style="margin:10px;"></div>
	<div id="detailgrid" style="margin:10px;"></div>
	<script type="text/javascript">
	(function($){
			var JewOrder={
					toolbarOptions : function(){
						var c=this,event=function(item){
							if(item.id=="add"){
								c.editData();
							}else{
								var selected=c.getSelected();
								if(selected){
									if(item.id=="delete"){
										$.ligerDialog.confirm("确定删除吗?<br />此操作将关联删除订单详情", function(confirm) {
											if (confirm){
												if(selected.id == ''){
													c.maingrid.deleteSelectedRow(selected);
													LG.showSuccess('删除成功');
												}else{
													LG.ajax({
														action : 'deletejeworder',
														loading : '正在删除中...',
														data : {
															'tgpo.id' : selected.id
														},
														success : function() {
															LG.showSuccess('删除成功');
															$this.maingrid.loadData();
														},
														error : function(message) {
															LG.showError(message);
														}
													});
												}
											}
										});
									}else{
										c.editData(selected.id);
									}
								}
							}
						};
						return {
							items : [
						          {	text : '增加',	icon : "add" , id:"add",click :event}, 
						          {line : true}, 
						          {text : '修改',icon : "modify",id:"modify",click : event}, 
						          {line : true},
						          {text : '删除',icon : "delete",id:"delete",click : event}
							]
						};
					},
					reloadDetail : function(id){
						//TODO 测试数据
						var testData={Rows:	[]};
						var consSize=parseInt(Math.random()*30);
						for(var i=0;i<consSize;i++){
							testData.Rows.push({"jeworderid": id,"jewtype":i+"123","status":"待分款"+i,"unitno":"1","styleno":i+"AAA"});
						}
						if(this.detailgrid)
							this.detailgrid.loadData(testData);
					},
					loadDetail:function(data){
						this.detailgrid = $("#detailgrid").ligerGrid({
							columns : [
									{display : '主键',name : 'id',hide:true},
									{display : '订单编号',name : 'jeworderid',editor: { type: 'text'}},
									{display : '状态',name : 'status',editor: { type: 'text'}},
									{display : '款号',name : 'styleno',editor: { type: 'text'}},
									{display : '首饰类别',	name : 'jewtype',editor: { type: 'text' }},
									{display : '件数',	name : 'unitno',editor: { type: 'text' }},
									{display : '手寸',	name : 'handinch',editor: { type: 'text' }},
									{display : '来主石',	name : 'ismstone',editor: { type: 'text' }},
									{display : '主石号',	name : 'mstoneid',editor: { type: 'text' }},
									{display : '主石名',	name : 'mstonename',editor: { type: 'text' }},
									{display : '主石规格',	name : 'mstonespec',editor: { type: 'text' }},
									{display : 'mstoneweight',	name : 'mstoneweight',editor: { type: 'text' }},
									{display : 'mstoneno',	name : 'mstoneno',editor: { type: 'text' }},
									{display : 'needstoneno',	name : 'needstoneno',editor: { type: 'text' }},
									{display : 'unit',	name : 'unit',editor: { type: 'text' }}
							],
							isScroll : false,
							rownumbers : true,
							enabledEdit: false,
							//url : 'tmp/jeworderlist.js',
							//url : 'getjeworder',
							data:{Rows:[]},
							sortName : 'id',
							title : '订单明细'
						});
						this.reloadDetail(data.Rows[0].id);
					},
					loadMainGrid:function(){
						var c=this,option=c.toolbarOptions();
						c.maingrid = $("#maingrid").ligerGrid({
							columns : [
									{display : '主键',name : 'id',	hide:true},
									{display : '制单人',name : 'makerid',type : 'text',editor: { type: 'text'}},
									{display : '提交时间',name : 'subtime',type : 'date',format: 'yyyy年MM月dd日'},
									{display : '状态',name : 'status',editor: { type: 'text' }},
									{display : '客户',name : 'clientid',editor: { type: 'text' }},
									{display : 'clientex',name : 'clientex',editor: { type: 'text' }},
									{display : '金属成色',name : 'metalper',editor: { type: 'text'}},
									{display : '金价',name : 'goldprice',type : 'float',editor: { type: 'float'}},
									{display : '字印',name : 'charprint',editor: { type: 'text'}},
									{display : '预付金',name : 'prepay',type : 'float',editor: { type: 'float'}},
									{display : '出货日',name : 'outdate',type : 'date',format: 'yyyy年MM月dd日'},
									{display : '收单人',name : 'receiverid',editor: { type: 'text' }},
									{display : '备注',name : 'note',editor: { type: 'text' }}
							],
							isScroll : true,
							checkbox : false,
							rownumbers : true,
							enabledEdit: true,
							clickToEdit:false,
							url : 'tmp/jeworderlist.js',
							//url : 'getjeworder',
							//data:{Rows:[]},
							sortName : 'id',
							toolbar : option,
							title : '首饰订单',
							onSelectRow:function(rowdata){
								c.reloadDetail(rowdata.id);
							},
							onSuccess:function(data,g){
								c.loadDetail(data);
							}
						});
					},
					getSelected :function(){
						var selected = this.maingrid.getSelected();
						if (!selected) {
							LG.tip('请选择行!');
							return false;
						}
						return selected;
					},
					editData:function(id){
						var location="./jewOrderEdit.jsp";
						if(id){
							location+="?id="+id;
						}
						document.location.href=location;
						//弹窗，暂时采用跳转
						//var option={height:600,width: 800,title : '打开窗口提示',url: "jewOrderEdit.jsp",showMax: false,showToggle: true,showMin: false,isResize: true,slide: false,data: {},myDataName: $("#txtValue").val()};
						//$.ligerDialog.open(option);
					},
					render:function(){
						this.loadMainGrid();
					}
			};
			$(document).ready(function(){
				JewOrder.render();
			});
	})(jQuery);
	</script>	
</body>
</html>
